﻿
using Chain.BLL;
using System;
using System.Data;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Wuqi.Webdiyer;

public partial class GiftsList : PageBase
{
    private ScoreMoneyAwards bllScoreMoneyAwards = new ScoreMoneyAwards();


    protected void drpPageSize_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.NetPagerParameter.CurrentPageIndex = 1;
        this.NetPagerParameter.PageSize = int.Parse(this.drpPageSize.SelectedValue);
        this.Get_ParameterList();
    }

    private void Get_ParameterList()
    {
        int Counts = this.NetPagerParameter.RecordCount;
        DataTable db = GetAwardsList(this.NetPagerParameter.PageSize, this.NetPagerParameter.CurrentPageIndex, out Counts).Tables[0];
        this.NetPagerParameter.RecordCount = Counts;
        this.NetPagerParameter.CustomInfoHTML = string.Format("<div class=\"results\"><span>当前第{0}/{1}页 共{2}条记录 每页{3}条</span></div>", new object[] { this.NetPagerParameter.CurrentPageIndex, this.NetPagerParameter.PageCount, this.NetPagerParameter.RecordCount, this.NetPagerParameter.PageSize });
        this.gvwGoodsClass.DataSource = db;
        this.gvwGoodsClass.DataBind();
        PageBase.BindSerialRepeater(this.gvwGoodsClass, this.NetPagerParameter.PageSize * (this.NetPagerParameter.CurrentPageIndex - 1));
    }

    protected void NetPagerParameter_PageChanging(object src, PageChangingEventArgs e)
    {
        this.NetPagerParameter.CurrentPageIndex = e.NewPageIndex;
        this.Get_ParameterList();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!base.IsPostBack)
        {
            this.Get_ParameterList();
        }
    }
    public DataSet GetAwardsList(int PageSize, int PageIndex, out int resCount)
    {
        System.Text.StringBuilder builder2 = new System.Text.StringBuilder();
        builder2.Append("select * from ( ");
        builder2.Append(" select ROW_NUMBER() over(order by status) as row,* from ( ");
        builder2.Append(" select  CONVERT(varchar(10),Nums) as value,case state when 1 then '积分' when 2 then '储值' else '其他' end as type,Status,ID from ScoreMoneyAwards where isdel=0 ");
        builder2.Append(" union all select  CONVERT(varchar(10),Level1)+'%,'+ ");
        builder2.Append(" case isnull(Level2,0) when 0 then '' else CONVERT(varchar(10),Level2)+'%,'end+ ");
        builder2.Append(" case isnull(Level3,0) when 0 then '' else CONVERT(varchar(10),Level3)+'%,'end as value, ");
        builder2.Append(" '返利' as type,Status,ID  from RebateAwards where isdel=0 ");
        builder2.Append(" union all ");
        builder2.Append(" select PresentsName as value,'小礼品' as type,Status,ID  from PresentAwards  where isdel=0 ");
        builder2.Append(" union all select ");
        builder2.Append(" case isnull(Score,0) when 0 then '' else  CONVERT(varchar(10),Score)+'积分,' end + ");
        builder2.Append(" case isnull(Money,0) when 0 then '' else  CONVERT(varchar(10),Money)+'储值,'end+ ");
        builder2.Append(" case isnull(WxPocket,0) when 0 then '' else CONVERT(varchar(10),WxPocket)+'红包'end as value, ");
        builder2.Append(" case state when 1 then '分享奖励' when 2 then '推广奖励' else '其他' end as type,Status,ID  from Share_ExtendAwards where isdel=0 ");
        builder2.Append(") test) as T ");
        DataSet ds = Chain.DBUtility.DbHelperSQL.Query(builder2.ToString());
        resCount = ds.Tables[0].Rows.Count;
        builder2.AppendFormat(" where T.row>={0} and T.row<{1}", (PageSize * (PageIndex - 1)) + 1, (PageSize * PageIndex) + 1);
        DataSet dt = Chain.DBUtility.DbHelperSQL.Query(builder2.ToString());
        return dt;

    }
}


